from pydantic_settings import BaseSettings
from typing import Optional
import secrets


class Settings(BaseSettings):
    """应用配置"""
    
    # 应用基本配置
    APP_NAME: str = "DataWorks 数据中台"
    APP_VERSION: str = "1.0.0"
    DEBUG: bool = False
    
    # 数据库配置
    DATABASE_URL: str = "postgresql://postgres:postgres123@localhost:5432/dataworks"
    
    # Redis 配置
    REDIS_URL: str = "redis://localhost:6379/0"
    
    # JWT 配置
    SECRET_KEY: str = secrets.token_urlsafe(32)
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
    ALGORITHM: str = "HS256"
    
    # 跨域配置
    ALLOWED_HOSTS: list = ["*"]
    
    # Airflow 配置
    AIRFLOW_API_URL: str = "http://localhost:8080/api/v1"
    AIRFLOW_USERNAME: str = "admin"
    AIRFLOW_PASSWORD: str = "admin123"
    
    # Doris 数据仓库配置
    DORIS_HOST: str = "127.0.0.1"
    DORIS_QUERY_PORT: int = 9030
    DORIS_HTTP_PORT: int = 8030
    DORIS_DATABASE: str = "edw"
    DORIS_USERNAME: str = "root"
    DORIS_PASSWORD: str = ""
    DORIS_CONNECTION_URL: str = f"mysql+pymysql://{DORIS_USERNAME}:{DORIS_PASSWORD}@{DORIS_HOST}:{DORIS_QUERY_PORT}/{DORIS_DATABASE}"
    
    # 文件存储配置
    UPLOAD_PATH: str = "./uploads"
    MAX_FILE_SIZE: int = 10 * 1024 * 1024  # 10MB
    
    # 日志配置
    LOG_LEVEL: str = "INFO"
    LOG_FILE: str = "./logs/app.log"
    
    class Config:
        env_file = ".env"
        case_sensitive = True


# 全局配置实例
settings = Settings() 